import request from "@/utils/request.js";

/**
 * 查询租户列表
 * @param params
 */
export const listTenant = params => {
  return request({
    url: "/dbo/system/tenant/list",
    method: "get",
    params
  });
};

/**
 * 查询租户详细
 * @param id
 */
export const getTenant = id => {
  return request({
    url: `/dbo/system/tenant/${id}`,
    method: "get"
  });
};

/**
 * 新增租户
 * @param data
 */
export const addTenant = data => {
  return request({
    url: "/dbo/system/tenant",
    method: "post",
    headers: {
      isEncrypt: true
    },
    data
  });
};

/**
 * 修改租户
 * @param data
 */
export const updateTenant = data => {
  return request({
    url: "/dbo/system/tenant",
    method: "put",
    data
  });
};

/**
 * 租户状态修改
 * @param id
 * @param tenantId
 * @param status
 * @returns {*}
 */
export const changeTenantStatus = (id, tenantId, status) => {
  const data = {
    id,
    tenantId,
    status
  };
  return request({
    url: "/dbo/system/tenant/changeStatus",
    method: "put",
    data
  });
};

/**
 * 删除租户
 * @param id
 */
export const delTenant = id => {
  return request({
    url: `/dbo/system/tenant/${id}`,
    method: "delete"
  });
};

/**
 * 动态切换租户
 */
export const dynamicTenant = tenantId => {
  return request({
    url: "/dbo/system/tenant/dynamic/" + tenantId,
    method: "get"
  });
};

/**
 * 清除动态租户
 * @returns {*}
 */
export const dynamicClear = () => {
  return request({
    url: "/dbo/system/tenant/dynamic/clear",
    method: "get"
  });
};

// 同步租户套餐
export const syncTenantPackage = (tenantId, packageId) => {
  const params = {
    tenantId,
    packageId
  };
  return request({
    url: "/dbo/system/tenant/syncTenantPackage",
    method: "get",
    params
  });
};
